﻿// CParamSetDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "MesTest.h"
#include "CParamSetDlg.h"
#include "afxdialogex.h"
#include "MesTestDlg.h"
#include "MesGSoap.h"


// CParamSetDlg 对话框

IMPLEMENT_DYNAMIC(CParamSetDlg, CDialogEx)

CParamSetDlg::CParamSetDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG1, pParent)
	, m_EDT_Port(0)
	, m_CHK_ProductCod(FALSE)
	, m_CHK_DanJiaCode(FALSE)
{
	
}

CParamSetDlg::~CParamSetDlg()
{
}

void CParamSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COM_PRODUCTTYPER, m_ProdectTypeR);
	DDX_Text(pDX, IDC_EDT_PORT, m_EDT_Port);
	DDX_Check(pDX, IDC_CHK_PRODUCTCODE, m_CHK_ProductCod);
	DDX_Check(pDX, IDC_CHK_DANJIACODE, m_CHK_DanJiaCode);
}


BEGIN_MESSAGE_MAP(CParamSetDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CParamSetDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BTN_FACTORYCODE, &CParamSetDlg::OnBnClickedBtnFactorycode)
	ON_BN_CLICKED(IDC_BTN_EQUIPMENTCODE, &CParamSetDlg::OnBnClickedBtnEquipmentcode)
	ON_BN_CLICKED(IDC_BTN_TESTCODE, &CParamSetDlg::OnBnClickedBtnTestcode)
	ON_BN_CLICKED(IDC_BTN_PRODUCTTYPE, &CParamSetDlg::OnBnClickedBtnProducttype)
	ON_BN_CLICKED(IDC_BTN_PRODUCTIDEN, &CParamSetDlg::OnBnClickedBtnProductiden)
	ON_BN_CLICKED(IDC_BTN_DANJIACODE, &CParamSetDlg::OnBnClickedBtnDanjiacode)
	ON_BN_CLICKED(IDC_BTN_IP, &CParamSetDlg::OnBnClickedBtnIp)
	ON_BN_CLICKED(IDC_BTN_PORT, &CParamSetDlg::OnBnClickedBtnPort)
	ON_BN_CLICKED(IDC_BTN_MESOUTLOG, &CParamSetDlg::OnBnClickedBtnMesoutlog)
	ON_BN_CLICKED(IDC_BTN_MESLOAD, &CParamSetDlg::OnBnClickedBtnMesload)
END_MESSAGE_MAP()


// CParamSetDlg 消息处理程序


void CParamSetDlg::OnBnClickedOk()
{
	UpdateData(TRUE);
	g_ProductCod = m_CHK_ProductCod;
	g_DanJiaCode = m_CHK_DanJiaCode;
	WritePrivateProfileInt("SetReadWrite", "ProductCode", g_ProductCod, g_SystemPathPLC);
	WritePrivateProfileInt("SetReadWrite", "DanJiaCode", g_DanJiaCode, g_SystemPathPLC);
	// TODO: 在此添加控件通知处理程序代码
	CDialogEx::OnOK();
}

BOOL CParamSetDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	InitParam();
	PassType = 0;
	return TRUE;
}

void CParamSetDlg::InitParam()
{
	SetDlgItemText(IDC_EDT_FACTORYCODER, g_InfoMes.FactoryCode);
	SetDlgItemText(IDC_EDT_EQUIPMENTCODER, g_InfoMes.EquipmentCode);
	//SetDlgItemText(IDC_EDT_LOADCODE, g_InfoMes.UserName);
	SetDlgItemText(IDC_EDT_TESTCODER, g_InfoMes.TestCode);
	
	if (g_DanJiaCode == 1)
	{
		SetDlgItemText(IDC_EDT_DANJIACODER, g_SendMes.cstrBox1);
	}
	else
	{
		SetDlgItemText(IDC_EDT_DANJIACODER, g_InfoMes.DanJiaCode);
	}
	if (g_ProductCod == 1)
	{
		SetDlgItemText(IDC_EDT_PRODUCTIDENR, g_SendMes.cstrMaterialNum);
	}
	else
	{
		SetDlgItemText(IDC_EDT_PRODUCTIDENR, g_InfoMes.ProductIden);
	}
	SetDlgItemText(IDC_EDT_IP, g_InfoMes.IP);
	m_EDT_Port = g_InfoMes.Port;

	CString cstrItem;
	cstrItem.Format("%d", m_EDT_Port);
	SetDlgItemText(IDC_EDT_PORT, cstrItem);

	cstrItem.Format(_T("REWORK"));  //返修产品
	m_ProdectTypeR.AddString(cstrItem);
	cstrItem.Format(_T("TRIALPROD"));//试制产品
	m_ProdectTypeR.AddString(cstrItem);
	cstrItem.Format(_T("TEST"));// 试验工单
	m_ProdectTypeR.AddString(cstrItem);
	cstrItem.Format(_T("STANDARD"));  //量产
	m_ProdectTypeR.AddString(cstrItem);
	m_ProdectTypeR.SetCurSel(g_InfoMes.ProductType);
	if (g_Land.PassLevel != 3)
	{
		GetDlgItem(IDC_BTN_FACTORYCODE)->EnableWindow(0);
		GetDlgItem(IDC_BTN_EQUIPMENTCODE)->EnableWindow(0);
		GetDlgItem(IDC_BTN_TESTCODE)->EnableWindow(0);
		GetDlgItem(IDC_BTN_PRODUCTTYPE)->EnableWindow(0);
		//GetDlgItem(IDC_BTN_PRODUCTIDEN)->EnableWindow(0);
		//GetDlgItem(IDC_BTN_DANJIACODE)->EnableWindow(0);
		GetDlgItem(IDC_BTN_IP)->EnableWindow(0);
		GetDlgItem(IDC_BTN_PORT)->EnableWindow(0);
	}
	((CButton*)GetDlgItem(IDC_CHK_PRODUCTCODE))->SetCheck(g_ProductCod);
	((CButton*)GetDlgItem(IDC_CHK_DANJIACODE))->SetCheck(g_DanJiaCode);
	/*m_CHK_ProductCod = g_ProductCod;
	m_CHK_DanJiaCode = g_DanJiaCode;*/
}

void CParamSetDlg::OnBnClickedBtnFactorycode()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_FACTORYCODER, g_InfoMes.FactoryCode);
	WritePrivateProfileString("EquipmentInfo", "FactoryCode", g_InfoMes.FactoryCode, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnEquipmentcode()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_EQUIPMENTCODER, g_InfoMes.EquipmentCode);
	WritePrivateProfileString("EquipmentInfo", "EquipmentCode", g_InfoMes.EquipmentCode, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnTestcode()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_TESTCODER, g_InfoMes.TestCode);
	WritePrivateProfileString("EquipmentInfo", "TestCode", g_InfoMes.TestCode, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnProducttype()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	g_InfoMes.ProductType = m_ProdectTypeR.GetCurSel();
	WritePrivateProfileInt("EquipmentInfo", "ProductType", g_InfoMes.ProductType, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnProductiden()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_PRODUCTIDENR, g_InfoMes.ProductIden);
	WritePrivateProfileString("EquipmentInfo", "ProductIden", g_InfoMes.ProductIden, g_FilePathLog);

}


void CParamSetDlg::OnBnClickedBtnDanjiacode()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_DANJIACODER, g_InfoMes.DanJiaCode);
	WritePrivateProfileString("EquipmentInfo", "DanJiaCode", g_InfoMes.DanJiaCode, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnIp()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_IP, g_InfoMes.IP);
	WritePrivateProfileString("Server", "IP", g_InfoMes.IP, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnPort()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	g_InfoMes.Port = m_EDT_Port;
	WritePrivateProfileInt("Server", "Port", g_InfoMes.Port, g_FilePathLog);
}


void CParamSetDlg::OnBnClickedBtnMesoutlog()
{
	// TODO: 在此添加控件通知处理程序代码
	PassType = 0;
	SetDlgItemText(IDC_EDT_MESCOUNT, "");
	SetDlgItemText(IDC_EDT_ACCOUNTNUMBER, "");
	g_InfoMes.UserName = "";
	g_InfoMes.UserPassWord = "";
	/*GetDlgItem(IDC_BTN_FACTORYCODE)->EnableWindow(0);
	GetDlgItem(IDC_BTN_EQUIPMENTCODE)->EnableWindow(0);
	GetDlgItem(IDC_BTN_TESTCODE)->EnableWindow(0);
	GetDlgItem(IDC_BTN_PRODUCTTYPE)->EnableWindow(0);
	GetDlgItem(IDC_BTN_PRODUCTIDEN)->EnableWindow(0);
	GetDlgItem(IDC_BTN_DANJIACODE)->EnableWindow(0);
	GetDlgItem(IDC_BTN_IP)->EnableWindow(0);
	GetDlgItem(IDC_BTN_PORT)->EnableWindow(0);*/
}


void CParamSetDlg::OnBnClickedBtnMesload()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	GetDlgItemText(IDC_EDT_MESCOUNT, g_InfoMes.UserName);
	GetDlgItemText(IDC_EDT_MESPASS, g_InfoMes.UserPassWord);
	((CMesTestDlg*)g_pMainDialog)->SetsetMesAddrAndPort();
	((CMesTestDlg*)g_pMainDialog)->SendMES_USER_RIGHT_VERIFY();
	if (PassType == 1)
	{
		//GetDlgItem(IDC_BTN_FACTORYCODE)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_EQUIPMENTCODE)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_TESTCODE)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_PRODUCTTYPE)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_PRODUCTIDEN)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_DANJIACODE)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_IP)->EnableWindow(1);
		//GetDlgItem(IDC_BTN_PORT)->EnableWindow(1);
		AfxMessageBox("登录成功");
	}
	else
	{
		AfxMessageBox("登录失败");
	}

}
